package com.idudiao.sc.neo4j.service;

import lombok.extern.slf4j.Slf4j;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author songyinyin
 * @date 2019/6/5 18:45
 */
@Service
@Slf4j
public class Neo4jService {

    @Autowired
    private Driver driver;

    public StatementResult excuteCypherSql(String cypherSql, Object... args) {
        StatementResult result = null;
        try (Session session = driver.session()) {
            String sql = String.format(cypherSql, args);
            log.info("执行cypher --> " + sql);
            result = session.run(sql);
        } catch (Exception e) {
            throw e;
        }
        return result;
    }

    public void deleteLabel(String label) {
        excuteCypherSql("MATCH (r:%s) DETACH DELETE r", label);
    }
}
